using Godot;
using System;

public partial class NStoreInventoryPanel : NInventoryPanel
{
	//自定义信号
	[Signal] //买
	public delegate void buyItemEventHandler(NItem item);
	[Signal] //卖
	public delegate void sellItemEventHandler(NItem item);
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		base._Ready();
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		base._Process(delta);
	}

	public override void onGUIInput(InputEvent @event)
	{
		if (@event is InputEventMouseButton mb)
		{
			NItem sellItem = GetTree().GetFirstNodeInGroup(NItem.CUR_SEL_ITEM) as NItem;
			if (mb.Pressed)
			{
				if (sellItem != null)
				{
					//卖
					NInventory inventory = GetTree().GetFirstNodeInGroup(nameof(NInventory)) as NInventory;
					inventory.mMoney+=sellItem.mItem.mMoney;
					sellItem.GetParent().RemoveChild(sellItem);
					sellItem.QueueFree();
				}
				else
				{
					//买
					NItem item = Item;
					if (item != null)
					{
						EmitSignal(SignalName.buyItem, item);
					}
				}
			}

		}
	}

}
